package com.hx.portal.controller.user;

import com.hx.common.exception.CustomerException;
import com.hx.common.result.Result;

import com.hx.hospital.pojo.ClinicCard;
import com.hx.hospital.service.ClinicCardService;
import io.swagger.annotations.*;

import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/clinic_card")
@RestController
@ResponseBody
@Api(description = "就诊卡相关接口文档")
public class ClinicCardController {

    @Reference
    private ClinicCardService clinicCardService;

    @PostMapping(value = "/insert")
    @ApiOperation(value = "添加",notes = "添加",httpMethod = "POST",authorizations = {@Authorization(value = "token")})
    public Result insert(@RequestBody ClinicCard clinicCard) throws CustomerException {
        clinicCardService.insert(clinicCard);
        return new Result();
    }

    @PostMapping(value = "/update")
    @ApiOperation(value = "修改",notes = "修改",httpMethod = "POST",authorizations = {@Authorization(value = "token")})
    public Result update(@RequestBody  ClinicCard clinicCard) throws CustomerException{
        clinicCardService.updateClinicCard(clinicCard);
        return new Result();
    }

    @PostMapping(value = "/defaultPeople")
    @ApiOperation(value = "修改默认",notes = "修改默认",httpMethod = "POST",authorizations = {@Authorization(value = "token")})
    public Result defaultPeople(@RequestBody  ClinicCard clinicCard) throws CustomerException{
        clinicCardService.updateClinicCardByRelationship(clinicCard);
        return new Result();
    }

    @PostMapping(value = "/delete")
    @ApiOperation(value = "删除",notes = "删除",httpMethod = "POST",authorizations = {@Authorization(value = "token")})
    @ApiImplicitParam(name = "id",value = "主键",paramType = "query")
    public Result delete(  Long id) throws CustomerException{
        clinicCardService.deleteClinicCard(id);
        return new Result();
    }

    @GetMapping(value = "/all")
    @ApiOperation(value = "查询",notes = "查询",httpMethod = "GET",authorizations = {@Authorization(value = "token")})
    @ApiImplicitParam(name = "userId",value = "外键",paramType = "query")
    public Result queryAll( Long userId) {
        List<ClinicCard> clinicCards = clinicCardService.queryByUserId(userId);
        System.out.println(clinicCards);
        return  new Result(clinicCards);
    }


}
